home *** CD-ROM | disk | FTP | other *** search
- /*
- * Copyright 1991, 1992, 1993, 1994, Silicon Graphics, Inc.
- * All Rights Reserved.
- *
- * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
- * the contents of this file may not be disclosed to third parties, copied or
- * duplicated in any form, in whole or in part, without the prior written
- * permission of Silicon Graphics, Inc.
- *
- * RESTRICTED RIGHTS LEGEND:
- * Use, duplication or disclosure by the Government is subject to restrictions
- * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
- * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
- * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
- * rights reserved under the Copyright Laws of the United States.
- */
- /*
- * pscal -
- * Make a calendar with an image.
- *
- * Paul Haeberli - 1993
- *
- *
- */
- #include <stdio.h>
- #include <math.h>
- #include "image.h"
-
- #define DRAWBORDER (0)
-
- #define BARDY (0.2)
- #define TOPY ((11.0-BARDY)/2.0)
- #define BORDER (8.5/16)
-
- #define BOXDY ((TOPY-BORDER)/6.0)
- #define BOXDX ((8.5-2*BORDER)/7.0)
-
- #define IXORG (BORDER)
- #define IYORG (TOPY+0.8)
- #define IXSIZE (8.5-2*BORDER)
- #define IYSIZE (11.0-BORDER-IYORG)
-
- char *monthnames[] = { "January", "February", "March", "April",
- "May", "June", "July", "August",
- "September", "October", "November", "December" };
-
- char *daynames[] = { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" };
-
- char monlength[] = { 0,
- 31, 29, 31, 30,
- 31, 30, 31, 31,
- 30, 31, 30, 31 };
-
- FILE *outf;
-
- main(argc, argv)
- char *argv[];
- {
- if(argc<4) {
- fprintf(stderr,"usage: pscal month year image.rgb\n");
- exit(1);
- }
- outf = fopen("/usr/tmp/PSCALTEMP.ps","w");
- if(!outf) {
- fprintf(stderr,"pscal: can't open outputfile /usr/tmp/PSCALTEMP.ps\n");
- exit(1);
- }
- drawcal(atoi(argv[1]),atoi(argv[2]),argv[3]);
- fclose(outf);
- system("lp < /usr/tmp/PSCALTEMP.ps");
- system("rm /usr/tmp/PSCALTEMP.ps");
- }
-
- IMAGE *inimage;
-
- psbwgetrow(buf,y)
- short *buf;
- int y;
- {
- getbwrow(inimage,buf,inimage->ysize-1-y);
- }
-
- int drawcal(mon,year,iname)
- int mon, year;
- char *iname;
- {
- int i, c;
- float ycoord;
- char tempstr[30];
- float xstart;
- int ixsize, iysize;
- float iaspect, paspect;
- float pxorg, pyorg;
- float pxsize, pysize;
-
- xstart = (8.5-7*BOXDX)/2.0;
-
- beginps(outf,8.5/11.0,0.0,8.5,0.0,11.0);
- psprintcortab();
-
- if(iname) {
- sizeofimage(iname,&ixsize,&iysize);
- paspect = (float)IXSIZE/IYSIZE;
- iaspect = (float)ixsize/iysize;
- if(iaspect>paspect) {
- pxsize = IXSIZE;
- pysize = (iysize*IXSIZE)/(float)ixsize;
- pxorg = IXORG;
- pyorg = IYORG+(IYSIZE-pysize)/2.0;
- } else {
- pysize = IYSIZE;
- pxsize = (ixsize*IYSIZE)/(float)iysize;
- pyorg = IYORG;
- pxorg = IXORG+(IXSIZE-pxsize)/2.0;
- }
- psgsave();
- pstranslate(pxorg,pyorg);
- psscale(pxsize,pysize);
- psgrey(0.0);
- inimage = iopen(iname,"r");
- if(!inimage) {
- fprintf(stderr,"pscal: can't open input image file %s\n",iname);
- exit(1);
- }
- tobwps(outf,psbwgetrow,0,8,ixsize,iysize);
- pslinewidth(0.0);
- if(DRAWBORDER)
- psrect(0.0,0.0,1.0,1.0);
- iclose(inimage);
- psgrestore();
- }
-
- pssetfont("Times-Roman",0.3);
- psgrey(0.0);
-
- sprintf(tempstr,"%s %u",monthnames[mon-1],year);
- psmoveto(xstart,TOPY+0.3);
- psshow(tempstr);
-
- pssetfont("Times-Italic",0.20);
- for (i=0; i<7; i++){
- psgrey(0.0);
- psrectf(xstart+BOXDX*i,TOPY,xstart+BOXDX*(i+1),TOPY+BARDY);
- psgrey(1.0);
- psmoveto(xstart+BOXDX/2.0+i*BOXDX,TOPY+0.05);
- pscentershow(daynames[i]);
- }
-
- c = dayofweek(mon, year);
- ycoord = TOPY;
- pslinewidth(0.0);
- pssetfont("Times-Roman",0.15);
- psgrey(0.0);
- for (i=1; i<=monlength[mon]; i++) {
- psmoveto(xstart+BOXDX*c+0.03,ycoord-0.15);
- sprintf(tempstr,"%2d",i);
- psshow(tempstr);
- psrect(xstart+BOXDX*c,ycoord,xstart+BOXDX*(c+1),ycoord-BOXDY);
-
- /* if finished with this line, drop down to next */
- if (++c == 7) {
- c = 0;
- ycoord -= BOXDY;
- }
- }
- endps();
- }
-
- dayofweek(m, y)
- {
- int d, i;
-
- d = jan1(y);
-
- if (((jan1(y+1)+7-d)%7) == 1)
- monlength[2] = 28;
- else
- monlength[2] = 29;
-
- for (i=1; i<m; i++)
- d += monlength[i];
-
- return d%7;
- }
-
- /*
- * return day of the week
- * of jan 1 of given year
- */
- jan1(y)
- int y;
- {
- int d;
-
- d = y + 4 + (y+3)/4;
- if (y > 1752) {
- d += 3;
- if (y > 1800) {
- d -= (y-1701)/100;
- d += (y-1601)/400;
- }
- }
- return d%7;
- }
-